package leecode;

import lombok.val;

import java.util.ArrayList;
import java.util.List;

public class _228 {
    public static void main(String[] args) {
        int[] ints = new int[]{0, 2, 3, 4, 6, 8, 9};
        val strings = summaryRanges(ints);
        System.out.println(strings);
    }

    public static List<String> summaryRanges(int[] nums) {
        List<String> res = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < nums.length; i++) {
            int current = nums[i];
            if (i == 0) {
                sb.append(current);
            }
            if (i < nums.length - 1) {
                int next = nums[i + 1];
                if (current + 1 != next) {
                    if (i != 0) {
                        if (!Integer.toString(current).contentEquals(sb)) {
                            sb.append("->");
                            sb.append(current);
                        }
                    }
//                    i++;
                    res.add(sb.toString());
                    sb = new StringBuilder();
                    sb.append(next);
                }
            } else {
                if (!Integer.toString(current).contentEquals(sb)) {
                    sb.append("->");
                    sb.append(current);
                }
                res.add(sb.toString());
            }
        }
        return res;
    }
}
